<?php
namespace Badmins\Controller;
use Think\Controller;
class AdvController extends Controller {
	/**
	 * 广告列表
	 */
    public function index(){
    	$listrow = (int)I('pageSize');
    	if(empty($listrow)){
    		$listrow = 15;
    	}
    	$where = array();
    	$name = I('name');
    	if(!empty($name)){
    		$where['name'] = array('like',"%{$name}%");
    	}
    	$p = I('pageCurrent/d')?I('pageCurrent/d'):'1';
    	$db = M('ad');
    	$count = $db->where($where)->count();
    	$firstrow = ($p-1)*$listrow;
    	$join = "left join __AD_PLACE__ as p on a.place_id = p.id";
    	$list = lists('ad as a',$join,$where,"a.*,p.name as placename","id desc",$firstrow,$listrow,2);
    	if($count>$listrow){
    		$show['total'] = $count;
    		$show['listrow'] = $listrow;
    		$this->assign('show',$show);
    	}
    	$this->assign('list',$list);
    	//广告位置
    	$map['status'] = 0;
    	$res = lists('ad_place','',$map,"id,name",'id desc', 0,0, 2);
    	$this->assign('res',$res);
        $this->display();
    }
    /**
     * 广告位置
     */
    public function seat(){
    	$listrow = (int)I('pageSize');
    	if(empty($listrow)){
    		$listrow = 15;
    	}
    	$where = array();
    	$name = I('name');
    	if(!empty($name)){
    		$where['name'] = array('like',"%{$name}%");
    	}
    	$p = I('pageCurrent/d')?I('pageCurrent/d'):'1';
    	$db = M('ad_place');
    	$count = $db->where($where)->count();
    	$firstrow = ($p-1)*$listrow;
    	$list = lists('ad_place','',$where,"*","id desc",$firstrow,$listrow,2);
    	if($count>$listrow){
    		$show['total'] = $count;
    		$show['listrow'] = $listrow;
    		$this->assign('show',$show);
    	}
    	$this->assign('list',$list);
    	$this->display();
    }
}


